﻿Imports System.Text
Imports Model
Imports Model.Geometry
Imports Model.Result
Imports Microsoft.Office.Interop.Excel

Public Class EXCELHelper
    Private Shared MyExcel As Microsoft.Office.Interop.Excel.Application
    Private Shared MyWokBook As Microsoft.Office.Interop.Excel.Workbook    '声明工作簿对象
    Private Shared MySheet As New Microsoft.Office.Interop.Excel.Worksheet    '声明工作表对象
    Private Shared Mypath As String
    Public Shared Function GetExcelApplicationCircle(ByVal propath As String)
        Dim pubpath As String
        pubpath = System.Environment.CurrentDirectory + "\docs\CircleTemplet.xls"
        MyExcel = New Microsoft.Office.Interop.Excel.Application
        MyExcel.Visible = True
        MyWokBook = MyExcel.Workbooks.Open(pubpath)
        MySheet = MyWokBook.Sheets("YK")
        Mypath = propath

        Return Nothing
    End Function
    Public Shared Function GetExcelApplicationHorse(ByVal propath As String)
        Dim pubpath As String
        pubpath = System.Environment.CurrentDirectory + "\docs\HorseTemplet.xls"
        MyExcel = New Microsoft.Office.Interop.Excel.Application
        MyExcel.Visible = True
        MyWokBook = MyExcel.Workbooks.Open(pubpath)
        MySheet = MyWokBook.Sheets("YK")
        Mypath = propath

        Return Nothing
    End Function

    Public Shared Function Writedata(ByVal mycircleresult As CircleResult, ByVal i As Integer)
        MySheet.Cells(7 + i, 1) = mycircleresult.stand_mil
        MySheet.Cells(7 + i, 3) = Math.Round(mycircleresult.design_center.p_y, 3).ToString()
        MySheet.Cells(7 + i, 4) = Math.Round(mycircleresult.design_center.p_x, 3).ToString()
        MySheet.Cells(7 + i, 5) = Math.Round(mycircleresult.suvery_center.p_y, 3).ToString()
        MySheet.Cells(7 + i, 6) = Math.Round(mycircleresult.suvery_center.p_x, 3).ToString()
        MySheet.Cells(7 + i, 7) = Math.Round(mycircleresult.suvery_center.p_x, 3).ToString() + "," + Math.Round(mycircleresult.suvery_center.p_y, 3).ToString()
        MySheet.Cells(7 + i, 8) = (Math.Round(mycircleresult.suvery_center.p_y * 1000) - Math.Round(mycircleresult.design_center.p_y * 1000)).ToString()
        MySheet.Cells(7 + i, 9) = (Math.Round(mycircleresult.suvery_center.p_x * 1000) - Math.Round(mycircleresult.design_center.p_x * 1000)).ToString()
        MySheet.Cells(7 + i, 10) = Math.Round(mycircleresult.stand_ele, 3).ToString()
        MySheet.Cells(7 + i, 11) = Math.Round(mycircleresult.design_max - mycircleresult.stand_ele, 3).ToString()
        MySheet.Cells(7 + i, 12) = Math.Round(mycircleresult.max_ele - mycircleresult.stand_ele, 3).ToString()
        MySheet.Cells(7 + i, 13) = Math.Round(mycircleresult.max_ele - mycircleresult.design_max, 3).ToString()
        MySheet.Cells(7 + i, 14) = Math.Round(mycircleresult.max_ele, 3).ToString()
        MySheet.Cells(7 + i, 15) = Math.Round(mycircleresult.stand_ele - mycircleresult.design_min, 3).ToString()
        MySheet.Cells(7 + i, 16) = Math.Round(mycircleresult.stand_ele - mycircleresult.min_ele, 3).ToString()
        MySheet.Cells(7 + i, 17) = Math.Round(mycircleresult.design_min - mycircleresult.min_ele, 3).ToString()
        MySheet.Cells(7 + i, 18) = Math.Round(mycircleresult.min_ele, 3).ToString()
        Return Nothing
    End Function
    Public Shared Function Writedata(ByVal myhorseresult As HorseResult, ByVal i As Integer)
        MySheet.Cells(7 + i, 1) = myhorseresult.stand_mil
        MySheet.Cells(7 + i, 3) = Math.Round(myhorseresult.design_center.p_y, 3).ToString()
        MySheet.Cells(7 + i, 4) = Math.Round(myhorseresult.design_center.p_x, 3).ToString()
        MySheet.Cells(7 + i, 5) = Math.Round(myhorseresult.suvery_center.p_y, 3).ToString()
        MySheet.Cells(7 + i, 6) = Math.Round(myhorseresult.suvery_center.p_x, 3).ToString()
        MySheet.Cells(7 + i, 7) = Math.Round(myhorseresult.suvery_center.p_x, 3).ToString() + "," + Math.Round(myhorseresult.suvery_center.p_y, 3).ToString()
        MySheet.Cells(7 + i, 8) = (Math.Round(myhorseresult.suvery_center.p_y * 1000) - Math.Round(myhorseresult.design_center.p_y * 1000)).ToString()
        MySheet.Cells(7 + i, 9) = (Math.Round(myhorseresult.suvery_center.p_x * 1000) - Math.Round(myhorseresult.design_center.p_x * 1000)).ToString()
        MySheet.Cells(7 + i, 10) = Math.Round(myhorseresult.stand_ele, 3).ToString()
        MySheet.Cells(7 + i, 11) = Math.Round(myhorseresult.design_max - myhorseresult.stand_ele, 3).ToString()
        MySheet.Cells(7 + i, 12) = Math.Round(myhorseresult.max_ele - myhorseresult.stand_ele, 3).ToString()
        MySheet.Cells(7 + i, 13) = Math.Round(myhorseresult.max_ele - myhorseresult.design_max, 3).ToString()
        MySheet.Cells(7 + i, 14) = Math.Round(myhorseresult.max_ele, 3).ToString()
        MySheet.Cells(7 + i, 15) = Math.Round(myhorseresult.stand_ele - myhorseresult.design_min, 3).ToString()
        MySheet.Cells(7 + i, 16) = Math.Round(myhorseresult.stand_ele - myhorseresult.min_ele, 3).ToString()
        MySheet.Cells(7 + i, 17) = Math.Round(myhorseresult.design_min - myhorseresult.min_ele, 3).ToString()
        MySheet.Cells(7 + i, 18) = Math.Round(myhorseresult.min_ele, 3).ToString()
        Return Nothing
    End Function

    Public Shared Function FinishWrite(ByVal time As String)
        MyWokBook.SaveAs(Mypath + "\result\" + time + "\EXCEL文件\断面成果检测表.xls", , , , , , , , , , , )
        Return Nothing
    End Function

    Public Shared Function Writedata(rectangleResult As RectangleResult, i As Integer) As Integer
        MySheet.Cells(6 + i, 1) = rectangleResult.stand_mil
        MySheet.Cells(6 + i, 2) = Math.Round(rectangleResult.design_CeGG, 3).ToString()
        MySheet.Cells(6 + i, 3) = Math.Round(rectangleResult.difCeGG, 3).ToString()
        MySheet.Cells(6 + i, 4) = (Math.Round((rectangleResult.difCeGG - rectangleResult.design_CeGG), 3) * 1000).ToString()

        MySheet.Cells(6 + i, 5) = Math.Round(rectangleResult.design_CeGG, 3).ToString()
        MySheet.Cells(6 + i, 6) = Math.Round(rectangleResult.difCeGG_21, 3).ToString()
        MySheet.Cells(6 + i, 7) = (Math.Round((rectangleResult.difCeGG_21 - rectangleResult.design_CeGG), 3) * 1000).ToString()

        MySheet.Cells(6 + i, 8) = Math.Round(rectangleResult.design_CeGG, 3).ToString()
        MySheet.Cells(6 + i, 9) = Math.Round(rectangleResult.difCeGG_42, 3).ToString()
        MySheet.Cells(6 + i, 10) = (Math.Round((rectangleResult.difCeGG_42 - rectangleResult.design_CeGG), 3) * 1000).ToString()

        MySheet.Cells(6 + i, 11) = Math.Round(rectangleResult.design_ZTH, 3).ToString()
        MySheet.Cells(6 + i, 12) = Math.Round(rectangleResult.dif_zth, 3).ToString()
        MySheet.Cells(6 + i, 13) = (Math.Round((rectangleResult.dif_zth - rectangleResult.design_ZTH), 3) * 1000).ToString()

        MySheet.Cells(6 + i, 14) = Math.Round(rectangleResult.design_difmax, 3).ToString()
        MySheet.Cells(6 + i, 15) = Math.Round(rectangleResult.difmax_ele, 3).ToString()
        MySheet.Cells(6 + i, 16) = (Math.Round((rectangleResult.difmax_ele - rectangleResult.design_difmax), 3) * 1000).ToString()

        MySheet.Cells(6 + i, 17) = Math.Round(rectangleResult.design_difmin, 3).ToString()
        MySheet.Cells(6 + i, 18) = Math.Round(rectangleResult.difmin_ele, 3).ToString()
        MySheet.Cells(6 + i, 19) = (Math.Round((rectangleResult.difmin_ele - rectangleResult.design_difmin), 3) * 1000).ToString()

        MySheet.Cells(6 + i, 20) = Math.Round(rectangleResult.design_ZTV, 3).ToString()
        MySheet.Cells(6 + i, 21) = Math.Round(rectangleResult.dif_ztv, 3).ToString()
        MySheet.Cells(6 + i, 22) = (Math.Round((rectangleResult.dif_ztv - rectangleResult.design_ZTV), 3) * 1000).ToString()

        Return Nothing
    End Function

    Shared Function GetExcelApplicationRectangle(propath As Object)
        Dim pubpath As String
        pubpath = System.Environment.CurrentDirectory + "\docs\RectangleTemplet.xls"
        MyExcel = New Microsoft.Office.Interop.Excel.Application
        MyExcel.Visible = True
        MyWokBook = MyExcel.Workbooks.Open(pubpath)
        MySheet = MyWokBook.Sheets("左")
        Mypath = propath

        Return Nothing
    End Function

End Class
